package org.example.browser;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.concurrent.TimeUnit;

import static java.lang.Thread.sleep;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-06-02
 * Time:17:23
 * Text：两种时间等待
 */
public class TimeTest {

    public static void Test1() throws InterruptedException {
        ChromeOptions options = new ChromeOptions();
        options.setBinary("D:\\Chrome\\chrome.exe");
        options.addArguments("--remote-allow-origins=*");
        WebDriver driver =new ChromeDriver(options);
        driver.get("https://www.baidu.com/");
        sleep(3000);
        driver.findElement(By.cssSelector("#kw")).sendKeys("我爱Java");
        driver.manage().timeouts().implicitlyWait(3, TimeUnit.DAYS);
        driver.findElement(By.cssSelector("#kw")).clear();
    }
    public static void main(String[] args) throws InterruptedException {
        //隐式等待
        Test1();
        //显式等待
        Test2();
    }

    private static void Test2() {
        ChromeOptions options = new ChromeOptions();
        options.setBinary("D:\\Chrome\\chrome.exe");
        options.addArguments("--remote-allow-origins=*");
        WebDriver webDriver = new ChromeDriver(options);
        webDriver.get("https://www.baidu.com/");
        WebDriverWait wait = new WebDriverWait(webDriver,3000);
        wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#bottom_layer > div > p:nth-child(8)")));

    }
}
